package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.Feedback;
import cn.stylefeng.guns.modular.entity.FeedbackClass;
import cn.stylefeng.guns.modular.service.IFeedbackClassService;
import cn.stylefeng.guns.modular.service.IFeedbackService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 反馈分类表 前端控制器
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-09
 */

@Controller
@RequestMapping("feedback-class")
public class FeedbackClassController extends BaseController {

    @Autowired
    private IFeedbackClassService feedbackClassService;

    private static String PREFIX = "/feedback-class/";

    /**
     * 跳转到反馈类型的首页
     */
    @RequestMapping
    public String index() {
        return PREFIX + "feedback_class.html";
    }

    /**
     * 新增
     */
    @RequestMapping(value = "add")
    public String add() {
        return PREFIX + "feedback_class_add.html";
    }

    /**
     * 修改
     */
    @RequestMapping(value = "edit/{id}")
    public ModelAndView update(@PathVariable Long id) {
        ModelAndView modelAndView = feedbackClassService.updateId(id);
        modelAndView.setViewName(PREFIX + "feedback_class_edit.html");
        return modelAndView;
    }

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("list")
    public LayuiPageInfo list() {
        Page page = LayuiPageFactory.defaultPage();
        //根据条件查询日志
        return feedbackClassService.getList(page);
    }

    /**
     * 创建类别
     */
    @ResponseBody
    @RequestMapping("add-class")
    public ResponseData addClass(@RequestBody FeedbackClass feedbackClass) {
        feedbackClassService.addClass(feedbackClass);
        return SUCCESS_TIP;
    }

    /**
     * 修改类别
     */
    @ResponseBody
    @RequestMapping("edit-class")
    public ResponseData updateClass(@RequestBody FeedbackClass feedbackClass) {
        feedbackClassService.updateClass(feedbackClass);
        return SUCCESS_TIP;
    }

    /**
     * 删除类别
     */
    @ResponseBody
    @RequestMapping("delete/{classId}")
    public ResponseData delete(@PathVariable Long classId) {
        feedbackClassService.delete(classId);
        return SUCCESS_TIP;
    }
}

